<div class="row content-nav">
    <div class="col-xs-12">
        <ul>
            <li><a href="javascript:;"><i></i>&nbsp;订单管理</a></li>
            <li><a href="javascript:;">订单列表</a></li>
        </ul>
    </div>
</div>

<div class="layui-fluid" id="search-box">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form layui-form-pane" action="">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label seller-inline-2">订单状态：</label>
                        <div class="layui-input-inline seller-inline-4">
                            <select name="status">
                                <option value="">全部</option>
                                 {if !empty($status_list)}
                                  {volist name="status_list" id="item"}
                                    <option value="{$key}">{$item}</option>
                                  {/volist}
                                 {/if}
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label seller-inline-2">订单号：</label>
                        <div class="layui-input-inline seller-inline-4">
                            <input type="text" name="order_no" placeholder="请输入订单号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label seller-inline-2">任务单号：</label>
                        <div class="layui-input-inline seller-inline-4">
                            <input type="text" name="job_no" placeholder="请输入任务单号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label seller-inline-2">用户账号：</label>
                        <div class="layui-input-inline seller-inline-4">
                            <input type="text" name="username" placeholder="请输入用户名" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-inline">
                      <label class="layui-form-label">提交时间：</label>
                      <div class="layui-input-inline" style="width:300px;">
                        <input type="text" class="layui-input" id="submit_time" name="submit_time" placeholder=" - ">
                      </div>
                    </div>
                    <div class="layui-inline">
                      <label class="layui-form-label">维权时间：</label>
                      <div class="layui-input-inline" style="width:300px;">
                        <input type="text" class="layui-input" id="appeal_time" name="appeal_time" placeholder=" - ">
                      </div>
                    </div>
                    <div class="layui-inline">
                        <button type="button" id="search-btn" class="layui-btn layui-btn-sm layui-bg-light-blue"><i class="layui-icon layui-icon-search"></i> 搜索</button>
                    </div>
                </div>

            </form>
        </div>
    </div>
</div>

<section class="content clearfix">
    <div class="layui-list-box">
        <table class="layui-hide" id="list-box" lay-filter="list-box"></table>
    </div>
</section>

<script type="text/html" id="list-toolbar">
    <div class="layui-btn-container">
        <button lay-event="refresh" type="button" class="layui-btn layui-btn-sm layui-bg-red"><i class="layui-icon">&#xe9aa;</i> 刷新</button>
    </div>
</script>



<script>
    layui.use(['table','form','laydate'], function () {
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;
        laydate.render({
            elem: '#submit_time'
            ,type: 'datetime'
            ,range: '~'
        });

        laydate.render({
            elem: '#appeal_time'
            ,type: 'datetime'
            ,range: '~'
        });

        table.render({
            elem: '#list-box'
            , url: '{:createUrl("index")}'
            , toolbar: '#list-toolbar'
            , defaultToolbar: []
            , title: '数据表'
            , cols: [[
                {type: 'checkbox'}
                , {title: '任务名',width:130, templet: function(res){
                        var str = res.job.name;
                        str = '<font attr-job-click-id=' + res.job.id + ' style="cursor:pointer">' + str + '</font>';
                        return str;
                    }}
                , {field: 'username', title: '用户',width:180}
                , {field: 'failure_reason', title: '不通过原因',align:'center'}
                , {field: 'status_name', title: '状态',width:200,align:'center'}
                , {field: 'createTime', title: '接单时间',width:130,align:'center'}
                , {field: 'submitTime', title: '提交时间',width:130,align:'center'}
                , {field: 'appealTime', title: '维权时间',width:130,align:'center'}
                , {title: '自动处理',width:130, align: 'center', templet: function(res){

                        var str = '';
                        if(res.is_closed || res.status==4){
                            str += '-';
                        } else {
                            str += res.waitTxpire;
                        }
                        return str;
                    }}
                , {title: '已付款',width:90, align: 'center', templet: function(res){

                        var str = '';
                        if(res.is_closed){
                            str += res.amount - 0;
                        } else {
                            str += '-';
                        }
                        return str;
                    }}
                , { title: '验证图',align:'center',templet: function(res){
                            return '<font attr-field= "res_job_images"><div>' + res.job.images + "</div></font>";
                        }}
                , {field: 'images', title: '完成图',align:'center'}
                , {fixed: 'right', align: 'center', title: '操作', width: 100, templet: function(res){
                        var str = '';
                        if(res.status==4){
                            str += '<a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="judge" >判罚</a>';
                        }
                        return str;
                    }}

            ]]
            , done: function (res) {

                $('td[data-field=images],font[attr-field=res_job_images]').each(function () {
                    $div = $(this).find('div');
                    var images = $div.html();

                    $div.html('');
                    //    $div.parent().parent().parent().css({'height':"50px"})

                    if(images) {
                        images = images.split('|');
                        for(let i in images){
                            image = images[i].split(',');
                            $div.append('<img style="height:30px;margin-right:5px;" attr-type="2" attr-src-big="' + image[1] + '" src="' + image[0] + '">')
                        }
                    }
                    $div.find('img[attr-type=2]').click(function(){
                        showBig($(this).attr('attr-src-big'));
                    })
                })

                // 显示详情
                $("td font[attr-job-click-id]").click(function () {
                    var id = $(this).attr('attr-job-click-id');
                    layer.open({
                        type: 2,
                        title: $(this).html(),
                        shadeClose: true,
                        shade: 0.3,
                        area: ['80%', '90%'],
                        content: '{:createUrl("job.index/details")}?id='+id
                    });
                })
            }
            , page: true
            , id: 'list-table'
            , height: 'full-310'
            // ,limit:30
        });

        $("#search-btn").on("click",function (){
            table.reload('list-table', {
                page: {
                    curr: 1
                }
                ,where: {
                    key: {
                        status : $('[name="status"]').val(),
                        order_no : $('[name="order_no"]').val(),
                        job_no : $('[name="job_no"]').val(),
                        username : $('[name="username"]').val(),
                        submit_time : $('[name="submit_time"]').val(),
                        appeal_time : $('[name="appeal_time"]').val(),
                    }
                }
            }, 'data');
        });

        //头工具栏事件
        table.on('toolbar(list-box)', function (obj) {
            switch (obj.event) {
                case 'url':
                    window.location.href = "{:createUrl('editor')}";
                    break;
                case 'refresh':
                    window.location.reload();
                    break;
            }
        });

        //监听行工具事件
        table.on('tool(list-box)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('你确定要删除吗？', function (index) {
                    $.get('{:createUrl("delete")}',{
                        id : data.id
                    },function(result){
                        layer.close(index);
                        if(result.code){
                            obj.del();
                        }else{
                            layer.msg(result.msg,{ icon : 2 });
                        }
                    },"json");
                });
            } else if (obj.event === 'edit') {
                window.location.href = '{:createUrl("detail")}?id='+data.id;
            }else if(obj.event == 'judge'){
                layer.open({
                    type: 2,
                    title: '判罚',
                    shadeClose: true,
                    shade: 0.3,
                    area: ['25%', '48%'],
                    content: '{:createUrl("judge")}?id='+data.id
                });
            }else if(obj.event == 'logistics'){
                layer.open({
                    type: 2,
                    title: '物流查询',
                    shadeClose: true,
                    shade: 0.3,
                    area: ['60%', '58%'],
                    content: '{:createUrl("express")}?id='+data.id
                });
            }
        });

    });

    function showBig(src) {
        layer.photos({
            photos: {"data": [{"src":src}]},
            anim: 0
        });
    }
</script>





